// OneCharEdit.cpp : implementation file
//

#include "stdafx.h"
#include "ansieditor.h"
#include "OneCharEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COneCharEdit

COneCharEdit::COneCharEdit()
{
	m_c1 = 0;
	m_bImeChar = FALSE;
}

COneCharEdit::~COneCharEdit()
{
}


BEGIN_MESSAGE_MAP(COneCharEdit, CEdit)
	//{{AFX_MSG_MAP(COneCharEdit)
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
//	ON_MESSAGE(WM_IME_CHAR, OnImeChar)
	ON_MESSAGE(WM_IME_STARTCOMPOSITION, OnImeStartComposition)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COneCharEdit message handlers

LRESULT COneCharEdit::OnImeChar(WPARAM wParam, LPARAM lParam)
{
	char buf[3] = { 0 };
	char c1 = (char)(wParam >> 8), c2 = (char)wParam;
	if(c1)
	{
		buf[0] = c1;
		buf[1] = c2;
	}
	else
	{
		buf[0] = c2;
	}
	SetWindowText(buf);
	SetSel(3, 3);
	return 0;
}

void COneCharEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if(m_bImeChar)
	{
		m_c1 = (char)nChar;
		m_bImeChar = FALSE;
	}
	else
	{
		if(m_c1)
		{
			char buf[3] = { m_c1, (char)nChar, 0 };
			SetWindowText(buf);
		}
		else
		{
			char buf[2] = { (char)nChar, 0 };
			SetWindowText(buf);
		}
		SetSel(3, 3);
		m_c1 = 0;
	}
}

LRESULT COneCharEdit::OnImeStartComposition(WPARAM wParam, LPARAM lParam)
{
	m_bImeChar = TRUE;
	return 0;
}